home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / dflt14.zip / BUTTON.C < prev    next >
Text File  |  1992-04-22  |  3KB  |  89 lines

  1. /* -------------- button.c -------------- */
  2.  
  3. #include "dflat.h"
  4.  
  5. void PaintMsg(WINDOW wnd, CTLWINDOW *ct, RECT *rc)
  6. {
  7.     if (isVisible(wnd))    {
  8.         if (TestAttribute(wnd, SHADOW) && cfg.mono == 0)    {
  9.             /* -------- draw the button's shadow ------- */
  10.             int x;
  11.             background = WndBackground(GetParent(wnd));
  12.             foreground = BLACK;
  13.             for (x = 1; x <= WindowWidth(wnd); x++)
  14.                 wputch(wnd, 223, x, 1);
  15.             wputch(wnd, 220, WindowWidth(wnd), 0);
  16.         }
  17.         if (ct->itext != NULL)    {
  18.             unsigned char *txt;
  19.             txt = DFcalloc(1, strlen(ct->itext)+10);
  20.             if (ct->setting == OFF)    {
  21.                 txt[0] = CHANGECOLOR;
  22.                 txt[1] = wnd->WindowColors
  23.                             [HILITE_COLOR] [FG] | 0x80;
  24.                 txt[2] = wnd->WindowColors
  25.                             [STD_COLOR] [BG] | 0x80;
  26.             }
  27.             CopyCommand(txt+strlen(txt),ct->itext,!ct->setting,
  28.                 WndBackground(wnd));
  29.             SendMessage(wnd, CLEARTEXT, 0, 0);
  30.             SendMessage(wnd, ADDTEXT, (PARAM) txt, 0);
  31.             free(txt);
  32.         }
  33.         /* --------- write the button's text ------- */
  34.         WriteTextLine(wnd, rc, 0, wnd == inFocus);
  35.     }
  36. }
  37.  
  38. void LeftButtonMsg(WINDOW wnd, MESSAGE msg, CTLWINDOW *ct)
  39. {
  40.     if (cfg.mono == 0)    {
  41.         /* --------- draw a pushed button -------- */
  42.         int x;
  43.         background = WndBackground(GetParent(wnd));
  44.         foreground = WndBackground(wnd);
  45.         wputch(wnd, ' ', 0, 0);
  46.         for (x = 0; x < WindowWidth(wnd); x++)    {
  47.             wputch(wnd, 220, x+1, 0);
  48.             wputch(wnd, 223, x+1, 1);
  49.         }
  50.     }
  51.     if (msg == LEFT_BUTTON)
  52.         SendMessage(NULL, WAITMOUSE, 0, 0);
  53.     else
  54.         SendMessage(NULL, WAITKEYBOARD, 0, 0);
  55.     SendMessage(wnd, PAINT, 0, 0);
  56.     if (ct->setting == ON)
  57.         PostMessage(GetParent(wnd), COMMAND, ct->command, 0);
  58.     else
  59.         beep();
  60. }
  61.  
  62. int ButtonProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  63. {
  64.     CTLWINDOW *ct = GetControl(wnd);
  65.     if (ct != NULL)    {
  66.         switch (msg)    {
  67.             case SETFOCUS:
  68.                 BaseWndProc(BUTTON, wnd, msg, p1, p2);
  69.                 p1 = 0;
  70.                 /* ------- fall through ------- */
  71.             case PAINT:
  72.                 PaintMsg(wnd, ct, (RECT*)p1);
  73.                 return TRUE;
  74.             case KEYBOARD:
  75.                 if (p1 != '\r')
  76.                     break;
  77.                 /* ---- fall through ---- */
  78.             case LEFT_BUTTON:
  79.                 LeftButtonMsg(wnd, msg, ct);
  80.                 return TRUE;
  81.             case HORIZSCROLL:
  82.                 return TRUE;
  83.             default:
  84.                 break;
  85.         }
  86.     }
  87.     return BaseWndProc(BUTTON, wnd, msg, p1, p2);
  88. }
  89.